home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Utils / GMSPrefs / TestPrefs.s < prev    next >
Encoding:
Text File  |  1997-07-08  |  7.5 KB  |  317 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Raining BOB's Demo
  3. ;------------------
  4. ;This is a demonstration of raining bobs, which I use as a test routine to
  5. ;see how fast some of my blitter routines are.  It's a good example of using
  6. ;MBOB's, try out different MAX_IMAGES values to see how many you can get on
  7. ;screen.  **120** 16 colour 16x8 bobs just manage to run at full speed on my
  8. ;A1200+FAST, change the value if you have a faster machine (600 can be very
  9. ;interesting :-).
  10. ;
  11. ;Technical notes
  12. ;---------------
  13. ;This demo takes direct advantage of some special GMS blitting features,
  14. ;such as restorelist clearing without masks (gain: 10%), and 16 pixel
  15. ;alignment (gain: 15%).  That allows us to have 25% more BOB's on screen!
  16. ;
  17. ;The fact that GMS will use the CPU to draw and clear images when the blitter
  18. ;is busy gives a boost of about 20%+ on an '020, so the overall advantage
  19. ;over a bog standard blitting function (eg BltBitmap()) is at least 40%.
  20. ;Given that such a function would have to be called 120 times with newly
  21. ;calculated parameters each time to draw, and 120 times to do the clears, we
  22. ;are probably looking at least 65% faster... is that good enough?
  23.  
  24.     INCDIR    "INCLUDES:"
  25.     INCLUDE    "games/games_lib.i"
  26.     INCLUDE    "games/games.i"
  27.  
  28. MAX_IMAGES =    120
  29.  
  30.     SECTION    "RainingBOBs",CODE
  31.  
  32. ;===========================================================================;
  33. ;                             INITIALISE DEMO
  34. ;===========================================================================;
  35.  
  36.     STARTGMS Test
  37.  
  38. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  39.     move.l    GMSBase(pc),a6
  40.     CALL    AllocBlitter
  41.     tst.l    d0
  42.     bne.s    .Error_Blitter
  43.  
  44.     lea    TAGS_BobsPicture(pc),a1
  45.     CALL    LoadPic
  46.     tst.l    d0
  47.     beq.s    .Error_Picture
  48.  
  49.     move.l    PIC_Bobs(pc),a1
  50.     move.w    PIC_Planes(a1),GPlanes+2
  51.     move.l    PIC_Palette(a1),GPalette
  52.  
  53.     lea    TAGS_Screen(pc),a0
  54.     CALL    AddScreen
  55.     move.l    d0,Screen
  56.     beq.s    .Error_Screen
  57.  
  58.     move.l    Screen(pc),a0
  59.     move.l    #MAX_IMAGES,d1    ;d1 = Maximum amount of images.
  60.     CALL    InitRestore
  61.     tst.l    d0
  62.     beq.s    .Error_Restorelist
  63.  
  64.     move.l    Screen(pc),a0
  65.     move.l    GS_Bitmap(a0),a0
  66.     lea    TAGS_RainBob(pc),a1
  67.     CALL    InitBob    ;>> = Initialise the Bob.
  68.     tst.l    d0
  69.     beq.s    .Error_RainBob
  70.  
  71.     move.l    Screen(pc),a0
  72.     CALL    ShowScreen
  73.  
  74.     CALL    InitJoyPorts
  75.  
  76.     bsr.s    Main
  77.  
  78. .ReturnToDOS
  79.     move.l    GMSBase(pc),a6
  80.     move.l    MBOB_Rain(pc),a1
  81.     CALL    FreeBob
  82. .Error_RainBob
  83.     move.l    Screen(pc),a0
  84.     CALL    FreeRestore
  85. .Error_Restorelist
  86.     move.l    Screen(pc),a0
  87.     CALL    DeleteScreen
  88. .Error_Screen
  89.     move.l    PIC_Bobs(pc),a1
  90.     CALL    FreePic
  91. .Error_Picture
  92.     CALL    FreeBlitter
  93. .Error_Blitter
  94.     MOVEM.L    (SP)+,A0-A6/D1-D7
  95.     moveq    #ERR_OK,d0
  96.     rts
  97.  
  98. ;===========================================================================;
  99. ;                                DEMO CODE
  100. ;===========================================================================;
  101.  
  102. Main:    moveq    #$00,d7
  103.     move.l    MBOB_Rain(pc),a1
  104.  
  105.     move.l    Screen(pc),a0    ;a0 = GameScreen.
  106.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  107.     move.w    MB_AmtEntries(a1),d2
  108.     subq.w    #1,d2
  109. .create    bsr    RegenerateBob
  110.  
  111.     move.w    GS_ScrHeight(a0),d1
  112.     CALL    FastRandom
  113.     move.w    d0,BE_YCoord(a2)
  114.  
  115.     lea    NBE_SIZEOF(a2),a2
  116.     dbra    d2,.create
  117.  
  118. ;---------------------------------------------------------------------------;
  119.  
  120. Loop:    addq.w    #1,d7
  121.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  122.     move.w    MB_AmtEntries(a1),d2
  123.     subq.w    #1,d2
  124. .update    bsr.s    UpdateBob
  125.     lea    NBE_SIZEOF(a2),a2
  126.     dbra    d2,.update
  127.  
  128.     move.l    Screen(pc),a0
  129.     move.l    GS_Bitmap(a0),a0
  130.     CALL    Restore
  131.  
  132.     move.l    MBOB_Rain(pc),a1    ;a1 = Bob to draw.
  133.     CALL    DrawBob    ;>> = Draw the mbob.
  134.  
  135.     CALL    WaitVBL    ;>> = Wait for VBL.
  136.  
  137.     move.l    Screen(pc),a0
  138.     CALL    SwapBuffers    ;>> = Swap the buffers.
  139.  
  140.     moveq    #JPORT1,d0    ;d0 = JoyPort2
  141.     moveq    #JT_ZBXY,d1    ;d1 = Bit switch type.
  142.     CALL    ReadJoyPort    ;>> = Go get port status.
  143.     btst    #MB_LMB,d0
  144.     beq.s    Loop
  145.     rts
  146.  
  147. ;===========================================================================;
  148. ;                               UPDATE A BOB
  149. ;===========================================================================;
  150. ;Function: Moves the entity according to its internal settings.
  151. ;Requires: a1 = Bob structure.
  152. ;       a2 = Entry to update.
  153.  
  154. UpdateBob:
  155.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  156.     add.w    BE_Speed(a2),d0    ;d0 = (YCoord)+YSpeed
  157.     cmp.w    GS_ScrHeight(a0),d0
  158.     blt.s    .YOkay
  159.     bsr    RegenerateBob
  160.     bra.s    .Animate
  161. .YOkay    move.w    d0,BE_YCoord(a2)
  162.  
  163. .Animate
  164.     tst.w    BE_Locked(a2)
  165.     beq.s    .exit
  166.     move.w    d7,d6
  167.     and.w    #%00000011,d6
  168.     bne.s    .exit
  169.     move.w    BE_FChange(a2),d1
  170.     bgt.s    .Positive
  171.  
  172. .Negative
  173.     cmp.w    #1,BE_Set(a2)
  174.     bgt.s    .NBlue
  175.     beq.s    .NGreen
  176. .NRed    add.w    d1,BE_Frame(a2)
  177.     tst    BE_Frame(a2)
  178.     bge.s    .exit
  179.     move.w    #1,BE_FChange(a2)
  180.     clr.w    BE_Frame(a2)
  181.     rts
  182. .NGreen    add.w    d1,BE_Frame(a2)
  183.     cmp.w    #4,BE_Frame(a2)
  184.     bge.s    .done
  185.     move.w    #1,BE_FChange(a2)
  186.     move.w    #4,BE_Frame(a2)
  187.     rts
  188. .NBlue    add.w    d1,BE_Frame(a2)
  189.     cmp.w    #8,BE_Frame(a2)
  190.     bge.s    .done
  191.     move.w    #1,BE_FChange(a2)
  192.     move.w    #8,BE_Frame(a2)
  193. .exit    rts
  194.  
  195. .Positive
  196.     cmp.w    #1,BE_Set(a2)
  197.     bgt.s    .PBlue
  198.     beq.s    .PGreen
  199. .PRed    add.w    d1,BE_Frame(a2)
  200.     cmp.w    #3,BE_Frame(a2)
  201.     ble.s    .done
  202.     move.w    #-1,BE_FChange(a2)
  203.     move.w    #2,BE_Frame(a2)
  204.     rts
  205. .PGreen    add.w    d1,BE_Frame(a2)
  206.     cmp.w    #7,BE_Frame(a2)
  207.     ble.s    .done
  208.     move.w    #-1,BE_FChange(a2)
  209.     move.w    #6,BE_Frame(a2)
  210.     rts
  211. .PBlue    add.w    d1,BE_Frame(a2)
  212.     cmp.w    #11,BE_Frame(a2)
  213.     ble.s    .done
  214.     move.w    #-1,BE_FChange(a2)
  215.     move.w    #10,BE_Frame(a2)
  216. .done    rts
  217.  
  218. ;===========================================================================;
  219. ;                            REGENERATE BOB ENTITY
  220. ;===========================================================================;
  221. ;Function: Regenerates an entity with completely new data.
  222. ;Requires: a2 = Entry to update.
  223.  
  224. RegenerateBob:
  225.     move.w    GS_ScrWidth(a0),d1
  226.     CALL    FastRandom
  227.     subq.w    #4,d0
  228.     and.w    #%1111111111111000,d0
  229.     move.w    d0,BE_XCoord(a2)
  230.  
  231.     moveq    #8,d1
  232.     CALL    FastRandom
  233.     addq.w    #2,d0
  234.     move.w    d0,BE_Speed(a2)
  235.  
  236.     moveq    #12,d1
  237.     CALL    FastRandom
  238.     move.w    d0,BE_Frame(a2)
  239.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  240.  
  241.     move.w    #-8,BE_YCoord(a2)
  242.     move.w    #1,BE_FChange(a2)
  243.     eor.w    #1,BE_Locked(a2)
  244.     rts
  245.  
  246. .Sets    dc.b    0,0,0,0
  247.     dc.b    1,1,1,1
  248.     dc.b    2,2,2,2
  249.  
  250. ;===========================================================================;
  251. ;                                  DATA
  252. ;===========================================================================;
  253.  
  254. TAGS_Screen:    dc.l  TAGS_GAMESCREEN
  255. Screen:        dc.l  0
  256.         dc.l  GSA_Palette
  257. GPalette:    dc.l  0
  258.         dc.l  GSA_Planes
  259. GPlanes:    dc.l  0
  260.         dc.l  GSA_Attrib,DBLBUFFER
  261.         dc.l  TAGEND
  262.  
  263. ;---------------------------------------------------------------------------;
  264.  
  265. TAGS_BobsPicture:
  266.         dc.l  TAGS_PICTURE
  267. PIC_Bobs:    dc.l  0
  268.         dc.l  PCA_Options,VIDEOMEM|GETPALETTE
  269.         dc.l  PCA_File,.file
  270.         dc.l  TAGEND
  271. .file        dc.b  "GMS:demos/data/PIC.Pulse",0
  272.         even
  273.  
  274. ;---------------------------------------------------------------------------;
  275.  
  276.   ;This is a mutated entrylist that we use for the raining bobs.
  277.  
  278.   STRUCTURE    NBE,BE_SIZEOF
  279.     WORD    BE_Speed    ;Speed of this particular bob.
  280.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  281.     WORD    BE_FChange
  282.     WORD    BE_Locked    ;Is it animated or not.
  283.     LABEL    NBE_SIZEOF
  284.  
  285. TAGS_RainBob:    dc.l  TAGS_MBOB
  286. MBOB_Rain:    dc.l  0
  287.         dc.l  MBA_AmtEntries,MAX_IMAGES
  288.         dc.l  MBA_GfxCoords,.frames
  289.         dc.l  MBA_Width,8
  290.         dc.l  MBA_Height,8
  291.         dc.l  MBA_EntryList,Images
  292.         dc.l  MBA_Attrib,CLIP|GENMASKS|CLEAR|CLRNOMASK
  293.         dc.l  MBA_PictureTags,TAGS_BobsPicture
  294.         dc.l  MBA_EntrySize,NBE_SIZEOF
  295.         dc.l  TAGEND
  296.  
  297. .frames        dc.w   0,8*0    ;RED
  298.         dc.w   0,8*1
  299.         dc.w   0,8*2
  300.         dc.w   0,8*3
  301.         dc.w   8,8*0    ;GREEN
  302.         dc.w   8,8*1
  303.         dc.w   8,8*2
  304.         dc.w   8,8*3
  305.         dc.w  16,8*0    ;BLUE
  306.         dc.w  16,8*1
  307.         dc.w  16,8*2
  308.         dc.w  16,8*3
  309.         dc.l  -1
  310.  
  311. ;---------------------------------------------------------------------------;
  312.  
  313.     SECTION    Images,BSS
  314.  
  315. Images:    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  316.  
  317.